package 题目集.二分;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * todo:重点题
 */
//https://pintia.cn/problem-sets/1745272598755459072/exam/problems/1745606572212137993?type=7&page=0
public class ch05_三足鼎立 {
    public static void main(String[] args) {
        Reader sc = new Reader();
        int n = sc.nextInt();
        long power = sc.nextLong();
        long[] arr = new long[n];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = sc.nextInt();
        }
        long count = getCount(arr, power);
        System.out.println(count);
    }

    private static long getCount(long[] arr, long power) {
        long count = 0;
        Arrays.sort(arr);
        int end= arr.length-1;
        for (int i = 0; i < arr.length - 1; i++) {
            long min=Math.abs(power - arr[i]);        //最小不能小于min
            int l = moreIndex(arr, i+1, end, min);    //最小边界
            if (l==-1){
                continue;
            }
            long max = power + arr[i];    //最大不能超过max
            int r = smallIndex(arr, i+1, end, max);   //最大边界
            if (l>r){
                continue;
            }
            count+=r-l+1;
        }
        return count;
    }
//    static {
//        int count=0;
//        Random r=new Random();
//        while (count-->0){
//            long[] arr=new long[r.nextInt(10)+1];
//            for (int i = 0; i < arr.length; i++) {
//                arr[i]=r.nextInt(100);
//            }
//            long power=r.nextInt(100);
//            long ans = ans(arr, power);
//            long issue = getCount(arr, power);
//            if (ans!=issue&&ans<10){
//                System.out.println("error");
//                System.out.println(Arrays.toString(arr));
//                System.out.println(power);
//                System.out.println("ans:"+ans);
//                System.out.println("issue:"+issue);
//            }
//        }
//    }
//    public static long ans(long[] arr, long power) {
//        int count = 10000;
//        for (int i = 0; i < arr.length - 1; i++) {
//            for (int j = i + 1; j < arr.length; j++) {
//                if (arr[i] + arr[j] > power && arr[i] + power > arr[j] && arr[j] + power > arr[i]) {
//                    count++;
//                }
//            }
//        }
//        return count;
//    }

    //从 l-r 中找到第一个小于t的数
    public static int smallIndex(long[] arr, int l, int r, long t) {
        int start=l;
        while (l <= r) {
            int mid = l + ((r - l) >> 1);
            if (t <= arr[mid]) {    //小于等于都认为是小于
                r = mid - 1;
            } else {
                l = mid + 1;
            }
        }
        if (r<start){
            return -1;
        }
        return r;
    }

    //从 l-r 中找到第一个大于t的数
    public static int moreIndex(long[] arr, int l, int r, long t) {
        while (l <= r) {
            int mid = l + ((r - l) >> 1);
            if (t >= arr[mid]) {    //大于等于都认为是大于
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        if (l>=arr.length) {
            return -1;
        }
        return l;
    }

//    static {
//        long[] nums = {0, 1, 2, 3, 4, 5};
//        int i = smallIndex(nums, 0, nums.length - 1, 10);
//    }

    static
    class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }

        public void clear() {
            tokenizer = new StringTokenizer("");
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
//    public BigInteger nextBigInt() {
//        return new BigInteger(next());
//    }
    }

}

